import { CategoryType, CourseType } from "@/types/course";
import request from "@/utils/request";
//新增类目
export const categoryPost = (cateObj: CategoryType) => {
  return request.post("classes/ReactCategory", cateObj);
};

//查询类目
export const categoryGet = (all: boolean) => {
  let where = all ? {} : { parentId: "0-0" };
  return request.get("classes/ReactCategory", {
    params: { where },
  });
};

//新增课程
export const coursePost = (courseObj: CourseType) => {
  return request.post("classes/ReactCourse", courseObj);
};

// 课程列表
interface ConditionType {
  name?: { $regex: string; $options: "i" };
  isvip?: string;
}
export const courseGet = ({ name, isvip }: ConditionType) => {
  let where = {} as ConditionType;
  if (name) {
    where.name = { $regex: `${name}`, $options: "i" };
  }
  if (isvip && isvip != "1") {
    where.isvip = isvip + "";
  }
  // let search = JSON.stringify(where);
  // return request.get(`classes/ReactCourse?where=${search}`);
  return request.get(`classes/ReactCourse`, {
    params: { where },
  });
};
